home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu022.dms
/
pu022.adf
/
Source
/
Source.LZH
/
saveiff.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-17
|
3KB
|
109 lines
#include "saveiff.h"
#include <iff/ilbm.h>
#include "chem_defs.h"
#include "messages.h"
/* ------------------------------- external references ------------------ */
extern struct ChemPrefs ChemPrefs;
extern void SimpleRequest();
/* ------------------------------- routines ----------------------------- */
LONG save(filename, screen, wwidth, sheight) /* saves displayed map as IFF FORM */
UBYTE *filename;
struct Screen *screen;
int wwidth, sheight;
{
IFFP PutAnILBM();
ULONG IconBase;
LONG file;
struct BitMap *picBitMap;
struct ViewPort *vp;
ULONG picViewModes;
WORD *picColorTable;
extern struct Screen *s;
IFFP iffp = NO_FILE;
LONG returncode = NOT_OK;
vp = &(screen->ViewPort);
if (!(file = Open(filename, MODE_NEWFILE)))
return (returncode);
Write(file, "x", 1); /* 1.1 so Seek to beginning works ? (?!?!???)*/
picBitMap = (struct BitMap *) vp->RasInfo->BitMap;
picColorTable = (WORD *) vp->ColorMap->ColorTable;
picViewModes = (ULONG) vp->Modes;
iffp = PutAnILBM(file, picBitMap, picColorTable, picBitMap->Depth,
picViewModes, wwidth, sheight);
Close(file);
if (iffp == IFF_OKAY)
{
if(ChemPrefs.IconCreaIFF==TRUE)
{
IconBase = (ULONG) OpenLibrary("icon.library", 0);
if (IconBase != NULL)
{
if (NULL != PutDiskObject(filename, &ILBMobject))
{
returncode = OK;
}
else
{
DisplayBeep(screen);
SimpleRequest(ERROR_PUT_ICON);
}
CloseLibrary((struct Library *) IconBase);
}
else
SimpleRequest(NO_ICON_LIB);
}
else
returncode=OK;
}
return (returncode);
}
#define CkErr(expression) {if (ifferr == IFF_OKAY) ifferr = (expression);}
IFFP PutAnILBM(file, bitmap, colorMap, depth,
viewmodes, wwidth, sheight)
LONG file;
struct BitMap *bitmap;
WORD *colorMap;
UBYTE depth;
ULONG viewmodes;
int wwidth, sheight;
{
BYTE buffer[bufsize];
BitMapHeader bmHdr;
CamgChunk camgChunk;
GroupContext fileContext, formContext;
IFFP ifferr;
ifferr = InitBMHdr(&bmHdr, bitmap, mskNone,
cmpByteRun1, 0, wwidth, sheight);
bmHdr.y = 0;
bmHdr.h = sheight;
camgChunk.ViewModes = viewmodes & CAMGMASK;
CkErr(OpenWIFF(file, &fileContext, szNotYetKnown));
CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext));
CkErr(PutBMHD(&formContext, &bmHdr));
CkErr(PutCAMG(&formContext, &camgChunk));
CkErr(PutCMAP(&formContext, colorMap, depth));
CkErr(PutBODY(&formContext, bitmap, mskNone, &bmHdr, buffer, bufsize));
CkErr(EndWGroup(&formContext));
CkErr(CloseWGroup(&fileContext));
return (ifferr);
}